package com.shuai.frame.protocol;

import lombok.Getter;

@Getter
public enum ProtocolMessageStatusEnum {
    // 这里的code值在自定义协议中作为byte类型使用，所以要注意数据范围：-128 - 127
    SUCCESS(20, "成功"),
    BAD_REQUEST(40, "badRequest"),
    BAD_RESPONSE(50, "badResponse"),
    ;
    private final int code;
    private final String desc;

    ProtocolMessageStatusEnum(int code, String desc) {
        this.code = code;
        this.desc = desc;
    }

    /**
     * 获取枚举
     */
    public static ProtocolMessageStatusEnum getEnum(int code) {
        for (ProtocolMessageStatusEnum statusEnum : ProtocolMessageStatusEnum.values()) {
            if (statusEnum.getCode() == code) {
                return statusEnum;
            }
        }
        return null;
    }
}
